Uec3.payInvoiceItemAddWin=Ext.extend(Ext.UecWindow,{

	constructor:function(config){
		this.getGrid();
		this.getSearchPanel();
		config=Ext.apply(config||{},{items:[this.searchPanel,this.grid]});
		Uec3.payInvoiceItemAddWin.superclass.constructor.call(this,config);
	},
	getGrid:function(){
		var record = Ext.data.Record.create(
	      	[{name : 'id',type : 'int'}, {name : 'companyId',type : 'int'},{name : 'customerId',type : 'int'},{name : 'code',type : 'string'}, 
	      	 {name : 'documentType',type : 'int'},{name : 'customerName',type : 'string'},{name : 'documentTypeVarName',type : 'string'}, 
	      	 {name : 'status',type : 'int'},{name : 'payable',type : 'double'},{name : 'paid',type : 'double'},{name : 'unPaid',type : 'double'}]);
		this.store = new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+'/payable/base!extList.do'}),
			pruneModifiedRecords : true,
			baseParams : {status:0},
			paramNames : {start : "start",limit : "limit",sort : "sort",dir : "dir"},
			reader : new Ext.data.JsonReader({totalProperty : 'totalProperty',root : 'root'}, record)
		});
		var columnModel = new Ext.grid.ColumnModel( [ new Ext.grid.RowNumberer(),
			{
			header:'操作',
			width:50,
			xtype:'anchorcolumn',
			dataIndex : 'act',
			items:[{
					text:"选中",
					scope:this,
					permissionId:25,
					handler:this.choose
				}]
			},
			{header : '应付款凭证号',width : 100,dataIndex : 'code'}, 
			{header : '供应商',width : 100,align:"left",dataIndex : 'customerName'}, 
			{header : '单据类型',width : 75,align:"left",dataIndex : 'documentTypeVarName'}, 
			{header : '应付总金额',width : 75,align:"right",dataIndex : 'payable'}, 
			{header : '已支付金额',width : 75,align:"right",dataIndex : 'paid'}, 
			{header : '未支付金额',width : 75,align:"right",dataIndex : 'unPaid'
		}]);
		this.grid=new Ext.grid.GridPanel(
		{
		cm : columnModel,
		viewConfig : {
			forceFit : true,
			getRowClass : function(record,rowIndex,rowParams,store){
				//禁用数据显示红色
				if(record.data.documentType==3){
					return 'x-grid-record-red';
				}else{
					return '';
				}
			}
		},
		store : this.store,
		selModel : new Ext.grid.RowSelectionModel( {
			moveEditorOnEnter : true
		}),
		flex:1,
		iconCls : 'icon-grid',
		loadMask : {msg : '数据加载中...'},
		stripeRows : true,
		autoScroll : true,
		bbar : new Ext.PagingToolbar({
			pageSize : 10,
			store : this.store,
			displayInfo : true,
			style : 'center',
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录"
		})
	});
	},
	getSearchPanel:function(){
		this.searchPanel=new Ext.FormPanel({
			frame:true,
			height:40,
			layout:"uec3grid",
    		layoutConfig:{
			    hGrid:[6,20,6,6,30],
			    vGrid:[100]
		    },
			items : [
				{xtype : 'label',text : '模糊查询:',style:'text-align:left;',grid:[1,1,1,1]},
				{xtype : 'textfield',name:'textSearchConditions',scope:this,emptyText : '多条件可用逗号或者空格隔开!',grid:[2,1,2,1],
	         	listeners : {
		        	'specialkey' : function(field, e) {
			    		if (e.getKey() == Ext.EventObject.ENTER) {
						this.search();
						}
					}
				}	
				},
				{xtype : 'button',text : '查询',scope:this,listeners:{'click':this.search},grid:[4,1,4,1]},
		  		{xtype:'label',text:'可查条件:应付款凭证号,供应商,单据类型',style:"color:#ff3333;font-size:14px",grid:[5,1,5,1]}
		  	]
		});
	},
	search:function(){
		var textSearchConditions=this.searchPanel.getForm().findField("textSearchConditions").getValue();
		this.store.baseParams.searchConditions=textSearchConditions;
		this.store.load();
	},
	initEvents:function(){
		Uec3.payInvoiceItemAddWin.superclass.initEvents.call(this);
		this.on("show",function(){
			if(this.params.customerId||this.params.ids){
		    	this.store.baseParams.customerId=this.params.customerId
		    	this.store.baseParams.idsnot=Ext.encode(this.params.idsnot);
				this.store.load();
    		}
		},this,{single:true});
		
	},
	choose:function(grid, rowIndex, colIndex, item, e){
   		var record=this.store.getAt(rowIndex);
   		if(this.params.window){
			var newRecord=this.params.window.getPayInvoiceItemRecord(record.data,0);
			this.params.window.payInvoiceItem_store.add(newRecord);
			this.close();
		}
    }
});

Uec3.payInvoiceItemAddWindow =  Ext.extend(Ext.app.Module, {
	id: 'payInvoiceItem_add',
	createWindow : function(params){
	    var uecId=this.createWindowUectId(params.winId);
        var desktop = this.app.getDesktop(); 
        var win = desktop.getWindowByUecId(uecId);
	        if(!win){ 
		        win = desktop.createWindowNoTaskMaxZIndex({
		            uecId: uecId,
		            title: '付款单明细查询',
		            width: 1000,
		           	height: 400,
		           	modal:true,
		           	params:params,
		            shim: false,
		            animCollapse: false,
		            constrainHeader: true,
		            maximizable: true,
		            layout: "vbox",
		            layoutConfig:{align:'stretch'}
		         },Uec3.payInvoiceItemAddWin);
	      } 
	      win.show();
   	}
});
